package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.response.RoleListResponseVO;
import com.yugong.service.RoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 角色控制器类
 *
 * @author yugong
 * @date 2024/2/23
 */
@RestController
@RequestMapping("/api/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    /**
     * 查询角色信息
     *
     * @return 角色信息
     */
    @GetMapping("/find-role")
    public Result findRole() {
        List<RoleListResponseVO> roleListResponseVOList = roleService.findRole();
        return Result.success(roleListResponseVOList);
    }

    /**
     * 根据角色名查询角色信息
     *
     * @param pageNum  当前页
     * @param pageSize 当前页数据个数
     * @param roleName 角色名
     * @return 角色信息
     */
    @GetMapping("/find-role-page")
    public Result findRolePage(@RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               @RequestParam String roleName) {
        PageInfo<RoleListResponseVO> roleListResponseVOPageInfo = roleService.findRole(pageNum, pageSize, roleName);
        return Result.success(roleListResponseVOPageInfo);
    }
}
